<?php

namespace app\pilot\controller;

use app\pilot\model\BalanceRecordModel;
use think\admin\Controller;

/**
 * 余额记录管理
 * @class Pilot
 * @package app\pilot\controller
 */
class BalanceRecord extends Controller
{
    /**
     * 余额记录列表
     * @auth true
     * @menu true
     */
    public function index()
    {
        $this->title = '余额记录列表';
        $this->type_dict = BalanceRecordModel::TYPE_DICT;
        BalanceRecordModel::mQuery()->alias('br')
            ->field('br.*')
            ->with(['pilot', 'task_order'])
            ->join('pilot p', 'br.pilot_id=p.id', 'left')
            ->join('task_order to', 'br.task_order_id=to.id', 'left')
            ->like('p.nickname#pilot_nickname,p.realname#pilot_realname')
            ->equal('br.status#status')
            ->dateBetween('br.create_at#create_at')
//            ->order('br.id desc')
            ->layTable();
    }

    /**
     * 列表数据处理
     * @param array $data
     */
    protected function _index_page_filter(array &$data)
    {
        foreach ($data as &$vo){
            if(isset($vo['type'])) $vo['type_text'] = BalanceRecordModel::TYPE_DICT[$vo['type']] ?? '';
        }
    }
}
